<?php

namespace app\middleware;

use Webman\MiddlewareInterface;
use Webman\Http\Request;
use Webman\Http\Response;

class AccessAuthMiddleware implements MiddlewareInterface
{
    public function process(Request $request, callable $next): Response
    {
        
        $response = $request->method() == 'OPTIONS' ? response('') : $next($request);

        // 给响应添加跨域相关的http头
        $response->withHeaders([
            'Access-Control-Allow-Origin' => '*',
            'Access-Control-Allow-Credentials' => 'true',
            'Access-Control-Allow-Headers' => 'authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With, Token, token,Xapptool-Version,Xapptool-Appkey,Xapptool-Fingerprint,Xapptool-debug',
            'Access-Control-Allow-Headers' => '*',
            'Access-Control-Allow-Methods' => '*'
        ]);
        return $response;
    }
}
